package com.airnewslinkosky.ticket.ui.lowerlevel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

import com.airnewslinkosky.ticket.R;
import com.airnewslinkosky.ticket.model.OfficeInfo;
import com.airnewslinkosky.ticket.ui.BaseActivity;
import com.airnewslinkosky.ticket.ui.Main;
import com.airnewslinkosky.ticket.util.FlyUtil;
import com.mobclick.android.MobclickAgent;

public class LowerLevelList extends BaseActivity implements OnClickListener,OnItemClickListener{
	
	public SimpleAdapter sa;
	public ListView lv;
	
	public static List<OfficeInfo> OfficeInfos = new ArrayList<OfficeInfo>();
	private List<Map<String,Object>> lowerList = new ArrayList<Map<String,Object>>();
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lower_level_list);
		// 删除窗口背景
        getWindow().setBackgroundDrawable(null);
        
		activityList.add(this);
		
		findViewById(R.id.backBut).setOnClickListener(this);
		for(OfficeInfo officeInfo : OfficeInfos){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("OfficeID", officeInfo.OfficeID);
			map.put("ParentOfficeID",officeInfo.ParentOfficeID);
			map.put("PlatformNo", officeInfo.PlatformNo);
			map.put("OfficeKey", officeInfo.OfficeKey);
			map.put("OfficeIVS", officeInfo.OfficeIVS);
			map.put("Email", officeInfo.Email);
			map.put("OfficeName", officeInfo.OfficeName);
			map.put("ContactName", officeInfo.ContactName);
			
			map.put("Telephone", officeInfo.Telephone);
			map.put("Mobile", officeInfo.Mobile);
			map.put("Fax", officeInfo.Fax);
			map.put("OfficeAddress", officeInfo.OfficeAddress);
			map.put("ZIP", officeInfo.ZIP);
			map.put("OfficeDescription", officeInfo.OfficeDescription);
			map.put("OfficeState", FlyUtil.getOfficeStateCodes(Integer.valueOf(officeInfo.OfficeState)));
			map.put("AllowAgent", officeInfo.AllowAgent);
			
			map.put("UserName", officeInfo.UserName);
			map.put("Password", officeInfo.Password);
			map.put("validateCode", officeInfo.validateCode);
			map.put("Remark", officeInfo.Remark);
			map.put("CreateTime", officeInfo.CreateTime);
			map.put("Sales", officeInfo.Sales);
			map.put("ProfitAccount", officeInfo.ProfitAccount);
			map.put("AuthorityModeNO", officeInfo.AuthorityModeNO);
			
			map.put("officeInfo", officeInfo);
			lowerList.add(map);
		}
		lv = (ListView) findViewById(R.id.levellist);
		
		sa = new SimpleAdapter(
				this,
				lowerList,
				R.layout.lower_level_row,
				new String[] { "OfficeName", "ContactName","OfficeState","Sales"},
				new int[] { R.id.OfficeName, R.id.ContactName,R.id.OfficeState,R.id.Sales}); 
		
		lv.setAdapter(sa);
		lv.setOnItemClickListener(this);
		
	}
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.backBut: 
			Intent intentR = new Intent();
			intentR.setClass(LowerLevelList.this, Main.class);
			startActivity(intentR);
			break;
		}
	}
	
	public void onItemClick(AdapterView<?> arg0, View v, int position,
			long arg3) {
		Map<String, Object> item = (Map<String, Object>) lv.getAdapter().getItem(position);
		Intent intent = new Intent();
		intent.setClass(LowerLevelList.this, LowerLevelDetail.class);
		LowerLevelDetail.officeInfo = (OfficeInfo)item.get("officeInfo");
		startActivity(intent);
	}
	
	public void onResume() {     
		super.onResume();     
		MobclickAgent.onResume(this); 
	}  
	
	public void onPause() {     
		super.onPause();     
		MobclickAgent.onPause(this); 
	}  
}
